package cn.ultrarisk.scadmin.manager.web.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * BaseController
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/4/30
 * @since V1.0
 */
public class BaseController {

    public ResponseEntity<String> getNotFoundResponseEntity() {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    }

    public ResponseEntity<String> getOkResponseEntity() {
        return new ResponseEntity<String>(HttpStatus.OK);
    }

    public <T> ResponseEntity<T> getOkResponseEntity(T o) {
        return new ResponseEntity<T>(o, HttpStatus.OK);
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public ResponseEntity<String> exception(HttpServletRequest request, Exception ex) {
        ex.printStackTrace();
        return new ResponseEntity<String>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
